﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core;
using System.Data;

namespace DataAccess.Classes
{
    public class BillDetail
    {
        #region Anh xa cac cot trong bang => thuoc tinh
        private string _MaHH;

        public string MaHH
        {
            get { return _MaHH; }
            set { _MaHH = value; }
        }

        private string _TenHH;

        public string TenHH
        {
            get { return _TenHH; }
            set { _TenHH = value; }
        }

        private int _Price;

        public int Price
        {
            get { return _Price; }
            set { _Price = value; }
        }
        private DateTime _Date;

        public DateTime Date
        {
            get { return _Date; }
            set { _Date = value; }
        }
        #endregion

        public static List<BillDetail> All(int ma)
        {
            IDataReader reader = null;
            try
            {

                reader = DataProvider.Instance.ExecuteReader("BillDetail_All", ma);

                return CBO.FillCollection<BillDetail>(reader);
            }
            catch
            {
                if (reader != null && reader.IsClosed == false)
                    reader.Close();
                return new List<BillDetail>();
            }
        }

        public static bool Delete(int ma, string maHH)
        {
            try
            {
                int rs = DataProvider.Instance.ExecuteNonQuery("BillDetail_Del", ma, maHH);
                return rs > 0;
            }
            catch
            {
                return false;
            }
        }

        public static string TotalAmount(int ma)
        {
            return DataProvider.Instance.ExecuteScalar("BillDetail_TotalAmount", ma).ToString();
        }
    }
}
